﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Kugar.Core.Network.Web;
using Kugar.MVC.DaemonUI.Controllers;
using WS.FlowAuth.Web.Data.DTO;
using WS.FlowAuth.Web.Data.EF;

namespace WS.FlowAuth.Web.Areas.Admin.Controllers
{
    public class AdminBaseController : WebUIBaseController
    {
        private RequestThreadLocal<FlowAuthEntities> _context = new RequestThreadLocal<FlowAuthEntities>(() => new FlowAuthEntities());

        private RequestThreadLocal<DTO_User> _currentUserID = new RequestThreadLocal<DTO_User>();

        public DTO_User CurrentUser
        {
            get { return _currentUserID.IsValueCreated ? _currentUserID.Value : null; }
            set
            {
                _currentUserID.Value = value;
               // Session["CurrentUser"] = value;
            }
        }

        protected FlowAuthEntities Context => _context.Value;

        protected override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            _context.Value.Dispose();

            base.OnResultExecuted(filterContext);
        }
    }
}